
/*
 * Author: Andrew Shore
 * CSCE 145 Section 004
 * Lab Test 2
 */
import java.util.Scanner;
public class BuildingManager {

	//user enters the name of the building they want to find and this method prints out the info
	public static void showBuildingInfo(Building[] building, String searchName){
		
		//loops through building array
		for(int index=0; index<building.length; index++){
			String otherName=building[index].getName();
			
			if(building[index]!=null){
			
			//if the name user gives is the same as the name of the building at that index info is printed
				if(searchName.equalsIgnoreCase(otherName)){
					System.out.print("Info found was: ");
					building[index].printInfo();
				}
			}
				//if it reaches end of array without finding hotel message is printed
			if(index==((building.length)-1)&& !searchName.equalsIgnoreCase(otherName)){
					System.out.println("Building not found.");
				}
			}
		}

		
	
	//this method prints the info of the building with the most floors
	public static void printBuildingWithMostFloors(Building[] building){
		int max=0;
		int maxIndex=0;
		//loops through array and checks to see if the floors at that index is larger than the max number of floors(which is 0 to begin with)
		for(int index=0; index<building.length; index++){
			if(building[index]!=null){
				int tempFloors=building[index].getFloors();
				
				if(tempFloors>max){
					max=tempFloors;
					maxIndex=index;
				}
			}
			
			
		}
		//prints the info of the building with most floors
		System.out.print("The building with the most floors is: ");
		building[maxIndex].printInfo();
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner keyboard=new Scanner(System.in);
		Building[] building;
		
		//variables to be used in constructing buildings
		String name;
		String city;
		int floors;
		int suites;
		int squareFootage;
		
		System.out.println("Welcome to the Building Manager.");  
		System.out.println("Please enter the number of buildings to be read:");
		int input=keyboard.nextInt();
		building=new Building[input];
		
		//loops through and prompts user to enter the building's information
			for(int index=0; index<building.length; index++){
				
				
				boolean isCorrect=false;
				//loops if user does not enter a valid choice
				while(!isCorrect){
					System.out.println("Data for Building "+(index+1));
				System.out.println("Type of Building (Hotel/Warehouse)?");
				String answer=keyboard.next();
				keyboard.nextLine();
				
				if(answer.equalsIgnoreCase("hotel")){
					System.out.println("Enter the hotel's name:");
					name=keyboard.nextLine();
					System.out.println("Enter the Hotel's city:");
					city=keyboard.nextLine();
					System.out.println("Enter the number of floors in "+name+":");
					floors=keyboard.nextInt();
					System.out.println("Enter the number of suites in "+name+":");
					suites=keyboard.nextInt();
					Hotel temp=new Hotel(name, city, floors, suites);
					building[index]=temp;
					isCorrect=true;
				}
				
				else if(answer.equalsIgnoreCase("warehouse")){
					System.out.println("Enter the Warehouse's name:");
					name=keyboard.nextLine();
					System.out.println("Enter the Warehouse's city:");
					city=keyboard.nextLine();
					System.out.println("Enter the number of floors in "+name+":");
					floors=keyboard.nextInt();
					System.out.println("Enter the square footage of "+name+":");
					squareFootage=keyboard.nextInt();
					Warehouse temp=new Warehouse(name, city, floors, squareFootage);
					building[index]=temp;
					isCorrect=true;
				}
				else{
					System.out.println("Invalid Input, please enter either 'hotel' or 'warehouse'.");
					isCorrect=false;
					
				}
				}
			}
			String answer="";
			//loops as long as user doesn't input exit
			while(!answer.equalsIgnoreCase("exit")){
				
				System.out.println("Enter choice ('showBuilding' to search for a particular building, 'mostFloors' to show the building with the most floors, or 'exit'" );
				answer=keyboard.next();
				keyboard.nextLine();
				
				//calls showBuilding method
				if(answer.equalsIgnoreCase("showBuilding")){
					System.out.println("Enter the building's name:");
					String choice=keyboard.nextLine();
					
					showBuildingInfo(building, choice);
					
				}
				//calls mostFloors method
				else if(answer.equalsIgnoreCase("mostFloors")) {
					printBuildingWithMostFloors(building);
				}
				else if(!answer.equalsIgnoreCase("exit")){
					System.out.println("Invalid input, please try again.");
				}
				
						
			}
	}

}
